package com.wyh.domain.vo.gfive.treeVo.tree_util;



import com.wyh.domain.vo.gfive.treeVo.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class ProjectRemoveNode {

    public static List<TreeNode> removeNodes(List<TreeNode> treeNodes) {
        if (treeNodes == null || treeNodes.isEmpty()) {
            return new ArrayList<>();
        }
        List<TreeNode> result = new ArrayList<>();
        for (TreeNode treeNode : treeNodes) {

            List<TreeNode> processedChildren = removeNodes(treeNode.getChildren());
            treeNode.setChildren(null);

            if (!(treeNode.getType().equals("room") || treeNode.getType().equals("parkingSpot")||
                    treeNode.getType().equals("layer")||treeNode.getType().equals("unit")
            ||treeNode.getType().equals("cluster")||treeNode.getType().equals("building"))) {
                treeNode.setChildren(processedChildren);
                result.add(treeNode);
            } else {

                result.addAll(processedChildren);
            }
        }

        return result;
    }
}
